#include <interface\gl.h>

#include "config.h"
#include "dialog.h"

dialog::dialog(string str, actor* act): content( str ),
                                            sdr( act ),
                                            txtlen( -1 ),
                                            myFont( NULL ),
                                            creationTime( clock() )
{}
dialog::~dialog(){}

clock_t dialog::getCreationTime(){ return creationTime; }

font* dialog::getFont(){return myFont;}
void dialog::setFont(font* ft){ myFont = ft; }

void dialog::display(){
        if( !myFont||!sdr ) return;
        f_coord_t coord = sdr->getFCoord();
        glPushMatrix();
        glEnable(GL_BLEND);
        if( txtlen == -1 ){
            glColor4f(0,0,0,0);
            glRasterPos(0,0);
            glPrint(myFont,content.c_str());
            txtlen = getRasterXi();
        }
        glTranslatef((int)(1.5*coord.X_coord*SCALE - txtlen/2),(int)(0.87*coord.Y_coord*SCALE+5),0);
        glColor4f(0,0,0,0.6);
        glBegin(GL_POLYGON);
            glVertex2i(0,0);
            glVertex2i(txtlen,0);
            glVertex2i(txtlen,13);
            glVertex2i(0,13);
        glEnd();
        glDisable(GL_BLEND);
        glPopMatrix();
        glColor4f(1,1,1,1);
        glRasterPos((int)(1.5*coord.X_coord*SCALE - txtlen/2 + 3),(int)(0.87*coord.Y_coord*SCALE+5+2));
        glPrint(myFont,content.c_str());
}
